<div class="middle">
  <div class="middle-header">
    <div class="container-fluid">
      <breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
      <alerts alerts="alerts"></alerts>
      <div>
        <h1 class="contains-actions">
          <div class="pull-right dropdown" ng-if="deployment" ng-hide="!('deployments' | canIDoAny)">
            <button type="button" class="dropdown-toggle btn btn-default actions-dropdown-btn hidden-xs" data-toggle="dropdown">
              Actions
              <span class="caret" aria-hidden="true"></span>
            </button>
            <a href=""
               class="dropdown-toggle actions-dropdown-kebab visible-xs-inline"
               data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i><span class="sr-only">Actions</span></a>
            <ul class="dropdown-menu dropdown-menu-right actions action-button">
              <li ng-if="!deployment.spec.paused && !updatingPausedState && (deploymentsVersion | canI : 'update')">
                <a href="" ng-click="setPaused(true)" role="button">Pause Rollouts</a>
              </li>
              <li ng-if="deployment.spec.paused && !updatingPausedState && (deploymentsVersion | canI : 'update')">
                <a href="" ng-click="setPaused(false)" role="button">Resume Rollouts</a>
              </li>
              <li class="divider" ng-if="!updatingPausedState && (deploymentsVersion | canI : 'update')"></li>
              <li ng-if="deploymentsVersion | canI : 'update'">
                <a ng-href="project/{{project.metadata.name}}/attach-pvc?kind=Deployment&name={{deployment.metadata.name}}&group=apps"
                   role="button">Add Storage</a>
              </li>
              <li ng-if="!autoscalers.length && (horizontalPodAutoscalersVersion | canI : 'create')">
                <!-- Create a new HPA. -->
                <a ng-href="project/{{projectName}}/edit/autoscaler?kind=Deployment&name={{deployment.metadata.name}}&group=apps"
                   role="button">Add Autoscaler</a>
              </li>
              <li ng-if="autoscalers.length === 1 && (horizontalPodAutoscalersVersion | canI : 'update')">
                <!-- Edit an existing HPA. -->
                <a ng-href="project/{{projectName}}/edit/autoscaler?kind=HorizontalPodAutoscaler&group=autoscaling&name={{autoscalers[0].metadata.name}}"
                  role="button">Edit Autoscaler</a>
              </li>
              <li ng-if="deploymentsVersion | canI : 'update'">
                <a ng-href="project/{{projectName}}/set-limits?kind=Deployment&name={{deployment.metadata.name}}&group=apps"
                  role="button">Edit Resource Limits</a>
              </li>
              <li ng-if="deploymentsVersion | canI : 'update'">
                <a ng-href="{{healthCheckURL}}" role="button">Edit Health Checks</a>
              </li>
              <li ng-if="deploymentsVersion | canI : 'update'">
                <a ng-href="{{deployment | editYamlURL}}" role="button">Edit YAML</a>
              </li>
              <li class="divider" ng-if="deploymentsVersion | canI : 'update'"></li>
              <li ng-if="deploymentsVersion | canI : 'delete'">
                <delete-link
                  kind="Deployment"
                  group="apps"
                  resource-name="{{deployment.metadata.name}}"
                  project-name="{{deployment.metadata.namespace}}"
                  alerts="alerts"
                  hpa-list="autoscalers">
                </delete-link>
              </li>
            </ul>
          </div>
          {{name}}
          <small class="meta" ng-if="deployment">created <span am-time-ago="deployment.metadata.creationTimestamp"></span></small>
        </h1>
        <labels labels="deployment.metadata.labels" clickable="true" kind="deployments" project-name="{{deployment.metadata.namespace}}" limit="3"></labels>
      </div>
    </div>
  </div><!-- /middle-header-->
  <div class="middle-content" persist-tab-state>
    <div class="container-fluid">
      <div ng-if="!loaded">Loading...</div>
      <div class="row" ng-if="loaded">
        <div class="col-md-12" ng-class="{ 'hide-tabs' : !deployment }">
          <div ng-if="deployment.spec.paused && !updatingPausedState" class="alert alert-info animate-if">
            <span class="pficon pficon-info" aria-hidden="true"></span>
            <strong>{{deployment.metadata.name}} is paused.</strong>
            This pauses any in-progress rollouts and stops new
            rollouts from running until the deployment is resumed.
            <span ng-if="!updatingPausedState && (deploymentsVersion | canI : 'update')" class="nowrap">
              <a href="" ng-click="setPaused(false)" role="button">Resume Rollouts</a>
            </span>
          </div>
          <uib-tabset>
            <uib-tab active="selectedTab.history">
              <uib-tab-heading>History</uib-tab-heading>
              <div class="table-filter-extension">
                <div class="data-toolbar">
                  <div class="data-toolbar-filter">
                    <project-filter></project-filter>
                  </div>
                </div>
              </div>
              <table class="table table-bordered table-mobile table-layout-fixed">
                <colgroup>
                  <col class="col-sm-2">
                  <col class="col-sm-4">
                  <col class="col-sm-3">
                  <col class="col-sm-3">
                </colgroup>
                <thead>
                  <tr>
                    <th>Version</th>
                    <th>Name</th>
                    <th>Replicas</th>
                    <th>Created</th>
                  </tr>
                </thead>
                <tbody ng-if="(replicaSetsForDeployment | size) == 0">
                  <tr><td colspan="4"><em>{{emptyMessage}}</em></td></tr>
                </tbody>
                <tbody ng-if="(replicaSetsForDeployment | size) > 0">
                  <tr ng-repeat="replicaSet in replicaSetsForDeployment">
                    <td data-title="Version">
                      #{{replicaSet | annotation : 'deployment.kubernetes.io/revision'}}
                    </td>
                    <td data-title="Name">
                      <a ng-href="{{replicaSet | navigateResourceURL}}">{{replicaSet.metadata.name}}</a>
                    </td>
                    <td data-title="Replicas">
                      <span ng-if="replicaSet.status.replicas !== replicaSet.spec.replicas">{{replicaSet.status.replicas}}/</span>{{replicaSet.spec.replicas}} replica<span ng-if="replicaSet.spec.replicas != 1">s</span>
                    </td>
                    <td data-title="Created">
                      <span am-time-ago="replicaSet.metadata.creationTimestamp"></span>
                    </td>
                  </tr>
                </tbody>
              </table>
            </uib-tab>
            <uib-tab active="selectedTab.configuration">
              <uib-tab-heading>Configuration</uib-tab-heading>
              <div class="resource-details" ng-if="deployment">
                <div class="row">
                  <div class="col-lg-6">
                    <!--
                      Show a header at lg and xl screen sizes to balance the columns, but hide
                      it at smaller widths since "Details" is not very meaningful.
                    -->
                    <h3 class="hidden visible-lg visible-xl">Details</h3>
                    <dl class="dl-horizontal left">
                      <dt>Selectors:</dt>
                      <dd>
                        <selector selector="deployment.spec.selector"></selector>
                      </dd>
                      <dt>Replicas:</dt>
                      <dd>
                        <replicas spec="deployment.spec.replicas"
                                  disable-scaling="inProgressDeployment || autoscalers.length"
                                  scale-fn="scale(replicas)"
                                  deployment="deployment"></replicas>
                        <span ng-if="autoscalers.length">(autoscaled)</span>
                        <div ng-if="deployment.status.updatedReplicas">
                          {{deployment.status.updatedReplicas}} up to date
                        </div>
                        <div ng-if="deployment.status.availableReplicas || deployment.status.unavailableReplicas">
                          <span ng-if="deployment.status.availableReplicas">{{deployment.status.availableReplicas}} available<span ng-if="deployment.status.unavailableReplicas">,</span></span>
                          <span ng-if="deployment.status.unavailableReplicas">{{deployment.status.unavailableReplicas}} unavailable</span>
                        </div>
                      </dd>
                      <dt>Strategy:</dt>
                      <dd>{{deployment.spec.strategy.type | sentenceCase}}</dd>
                      <dt ng-if-start="deployment.spec.strategy.rollingUpdate">
                        Max Unavailable:
                        <span data-toggle="tooltip"
                          title="The maximum number of pods that can be unavailable during the update process."
                          class="pficon pficon-help text-muted small"></span>
                      </dt>
                      <dd>
                        <span ng-if="deployment.spec.strategy.rollingUpdate.maxUnavailable | isNil">25%</span>
                        <span ng-if="!(deployment.spec.strategy.rollingUpdate.maxUnavailable | isNil)">
                          {{deployment.spec.strategy.rollingUpdate.maxUnavailable}}
                        </span>
                      </dd>
                      <dt>
                        Max Surge:
                        <span data-toggle="tooltip"
                          title="The maximum number of pods that can be created above the desired number of pods."
                          class="pficon pficon-help text-muted small"></span>
                      </dt>
                      <dd ng-if-end>
                        <span ng-if="deployment.spec.strategy.rollingUpdate.maxSurge | isNil">25%</span>
                        <span ng-if="!(deployment.spec.strategy.rollingUpdate.maxSurge | isNil)">
                          {{deployment.spec.strategy.rollingUpdate.maxSurge}}
                        </span>
                      </dd>
                      <dt>
                        Min Ready:
                        <span data-toggle="tooltip"
                          title="The minimum number of seconds a new pod must be ready before it is considered available."
                          class="pficon pficon-help text-muted small"></span>
                      </dt>
                      <dd>
                        {{deployment.spec.minReadySeconds || 0}} sec
                      </dd>
                      <dt>
                        Revision History Limit:
                        <span data-toggle="tooltip"
                          title="The number of old replica sets to keep."
                          class="pficon pficon-help text-muted small"></span>
                      </dt>
                      <dd>
                        {{deployment.spec.revisionHistoryLimit || 2}}
                      </dd>
                      <dt>
                        Progress Deadline:
                        <span data-toggle="tooltip"
                          title="The amount of time to wait for a deployment to make progress before it's considered failed."
                          class="pficon pficon-help text-muted small"></span>
                      </dt>
                      <dd>
                        {{deployment.spec.progressDeadlineSeconds || 600}} sec
                      </dd>
                    </dl>

                    <h3>Template</h3>
                    <pod-template
                        pod-template="deployment.spec.template"
                        images-by-docker-reference="imagesByDockerReference"
                        builds="builds"
                        detailed="true"
                        add-health-check-url="{{ (deploymentsVersion | canI : 'update') ? healthCheckURL : '' }}">
                    </pod-template>

                  </div>
                  <div class="col-lg-6">
                    <h3>Volumes</h3>
                    <p ng-if="!deployment.spec.template.spec.volumes.length && !(deploymentsVersion | canI : 'update')">
                      none
                    </p>
                    <volumes
                        volumes="deployment.spec.template.spec.volumes"
                        namespace="project.metadata.name"
                        can-remove="deploymentsVersion | canI : 'update'"
                        remove-fn="removeVolume(volume)">
                    </volumes>
                    <div ng-if="deploymentsVersion | canI : 'update'">
                      <a ng-href="project/{{project.metadata.name}}/attach-pvc?kind=Deployment&name={{deployment.metadata.name}}&group=apps">Add Storage</a>
                      <span class="action-divider" aria-hidden="true">|</span>
                      <a ng-href="project/{{project.metadata.name}}/add-config-volume?kind=Deployment&name={{deployment.metadata.name}}&group=apps">Add Config Files</a>
                    </div>

                    <h3>Autoscaling</h3>

                    <!-- Show any warnings. -->
                    <div ng-repeat="warning in hpaWarnings" class="alert alert-warning">
                      <span class="pficon pficon-warning-triangle-o" aria-hidden="true"></span>
                      <span class="sr-only">Warning:</span>
                      {{warning.message}}

                      <!-- If the CPU request is missing, add an action to set one. -->
                      <a ng-href="project/{{projectName}}/set-limits?kind=Deployment&name={{deployment.metadata.name}}&group=apps"
                         ng-if="warning.reason === 'NoCPURequest' && (deploymentsVersion | canI : 'update')"
                         role="button">Edit Resource
                        <span ng-if="!('cpu' | isRequestCalculated : project)">Requests and</span> Limits</a>
                    </div>

                    <!-- Create autoscaler -->
                    <div ng-if="!autoscalers.length">
                      <a ng-if="horizontalPodAutoscalersVersion | canI : 'create'" ng-href="project/{{projectName}}/edit/autoscaler?kind=Deployment&name={{deployment.metadata.name}}&group=apps"
                         role="button">Add Autoscaler</a>
                      <span ng-if="!(horizontalPodAutoscalersVersion | canI : 'create')">none</span>
                    </div>

                    <!-- HPA details -->
                    <div ng-repeat="hpa in autoscalers">
                      <hpa hpa="hpa" project="project" show-scale-target="false" alerts="alerts"></hpa>
                    </div>

                  </div>
                  <!-- Service Bindings -->
                  <div class="col-lg-6">
                    <resource-service-bindings
                      project="project"
                      project-context="projectContext"
                      api-object="deployment">
                    </resource-service-bindings>
                  </div>
                </div>
                <div class="mar-top-md">
                  <annotations annotations="deployment.metadata.annotations"></annotations>
                </div>
              </div>
            </uib-tab>
            <uib-tab heading="Environment" active="selectedTab.environment" ng-if="deployment">
              <uib-tab-heading>Environment</uib-tab-heading>
              <edit-environment-variables api-object="deployment"></edit-environment-variables>
            </uib-tab>
            <uib-tab active="selectedTab.events" ng-if="eventsVersion | canI : 'watch'">
              <uib-tab-heading>Events</uib-tab-heading>
              <events api-objects="[ deployment ]" project-context="projectContext" ng-if="selectedTab.events"></events>
            </uib-tab>
          </uib-tabset>
        </div><!-- /col-* -->
      </div>
    </div>
  </div><!-- /middle-content -->
</div>
